package cn.luckdou.system.model.we_chat_event;

import cn.luckdou.commons.utils.JsonUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;
import com.baomidou.mybatisplus.enums.IdType;
import java.util.Date;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableName;
import java.io.Serializable;
import java.util.Map;

/**
 * <p>
 * 微信用户事件
 * </p>
 *
 * @author Dadou
 * @since 2017-12-08
 */
@TableName("tb_we_chat_event")
public class WeChatEvent extends Model<WeChatEvent> {

    private static final long serialVersionUID = 1L;

    /**
     * id
     */
	@TableId(value="id", type= IdType.AUTO)
	private Long id;
    /**
     * openId
     */
	@TableField("open_id")
	private String openId;
    /**
     * 发生时间
     */
	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
	private Date time;
    /**
     * 类型
     */
	private String type;
    /**
     * 内容
     */
	private String data;
    /**
     * 状态 1正常 0停用
     */
	private Integer status;
    /**
     * 创建时间
     */
	@TableField("created_time")
	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
	private Date createdTime;
    /**
     * 修改时间
     */
	@TableField("updated_time")
	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
	private Date updatedTime;
    /**
     * 删除时间
     */
	@TableField("deleted_time")
	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
	private Date deletedTime;
    /**
     * 编辑人
     */
	@TableField("created_editor")
	private String createdEditor;
    /**
     * 更新人
     */
	@TableField("updated_editor")
	private String updatedEditor;
	/**
	 * 无参构造方法
	 */
	public WeChatEvent(){
	}

    public WeChatEvent(Map<String, String> map) {
		this.openId=map.get("FromUserName");
		this.time=new Date(Long.parseLong(map.get("CreateTime"))*1000);
		if (map.get("MsgType").equals("event"))
			this.type=map.get("Event");
		else
			this.type=map.get("MsgType");
		this.data= JsonUtils.objectToJson(map);
		this.createdTime=new Date();
	}

    public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getOpenId() {
		return openId;
	}

	public void setOpenId(String openId) {
		this.openId =StringUtils.isNotBlank(openId)?openId:null;
	}

	public Date getTime() {
		return time;
	}

	public void setTime(Date time) {
		this.time = time;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type =StringUtils.isNotBlank(type)?type:null;
	}

	public String getData() {
		return data;
	}

	public void setData(String data) {
		this.data =StringUtils.isNotBlank(data)?data:null;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public Date getCreatedTime() {
		return createdTime;
	}

	public void setCreatedTime(Date createdTime) {
		this.createdTime = createdTime;
	}

	public Date getUpdatedTime() {
		return updatedTime;
	}

	public void setUpdatedTime(Date updatedTime) {
		this.updatedTime = updatedTime;
	}

	public Date getDeletedTime() {
		return deletedTime;
	}

	public void setDeletedTime(Date deletedTime) {
		this.deletedTime = deletedTime;
	}

	public String getCreatedEditor() {
		return createdEditor;
	}

	public void setCreatedEditor(String createdEditor) {
		this.createdEditor =StringUtils.isNotBlank(createdEditor)?createdEditor:null;
	}

	public String getUpdatedEditor() {
		return updatedEditor;
	}

	public void setUpdatedEditor(String updatedEditor) {
		this.updatedEditor =StringUtils.isNotBlank(updatedEditor)?updatedEditor:null;
	}

	@Override
	protected Serializable pkVal() {
		return this.id;
	}

}
